import 'dart:io';

import 'package:flutter/material.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/tools_base/cache/image_cache_manager.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';

class VideoCoverSelectWidget extends StatelessWidget {
  final String cover;
  final double? ratio;
  final double? width;
  final double? height;
  final bool isLocal;
  final bool showMask;
  final int borderRadius;
  const VideoCoverSelectWidget(this.cover,
      {this.ratio, this.width, this.height, this.isLocal = false, this.showMask = false, this.borderRadius = 8});
  @override
  Widget build(BuildContext context) {
    final child = Stack(
      alignment: Alignment.center,
      children: [
        if (isLocal)
          Image.file(
            File(cover),
            width: width,
            height: width,
            fit: BoxFit.cover,
          )
        else
          NetworkImageLoader(imageUrl: cover, width: width ?? double.infinity, height: height ?? double.infinity, borderRadius: 0),
        if (showMask)
          Container(
            width: width ?? double.infinity,
            height: height ?? double.infinity,
            decoration: BoxDecoration(
              color: Colors.black.withOpacity(0.4),
            ),
          ),
      ],
    );
    return ClipRRect(
        borderRadius: BorderRadius.circular(borderRadius.toDouble()),
        child: ratio != null
            ? AspectRatio(
          aspectRatio: ratio! > 0 ? ratio! : 1,
          child: child,
        )
            : child);
  }
}
